<template>
  <div class="column-detail-page w-75 mx-auto">
    <div class="column-infor row mb-4 border-bottom pb-4 align-items-center" v-if="column">
      <div class="col-3 text-center">
        <img :src="column.avatar.url" :alt="column && column.title" class="rounded-circle border w-100">
      </div>
      <div class="col-9">
        <h4>{{column && column.title}}</h4>
        <p class="text-muted">{{column && column.description}}</p>
      </div>
    </div>
  </div>
  <postList :posts="list" />
</template>

<script lang="ts">
import { defineComponent, computed, onMounted } from 'vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import { GlobalDataProps } from '../store'
import PostList from '../components/PostList.vue'
export default defineComponent({
  components: { PostList },
  setup () {
    const store = useStore<GlobalDataProps>()
    const route = useRoute()
    const currentId = route.params.id
    onMounted(() => {
      const currentId = route.params.id
      store.dispatch('fetchColumn', currentId)
      store.dispatch('fetchPosts', currentId)
    })
    // const column = computed(() => store.state.columns.find(c => c.id === currentId))
    const column = computed(() => store.getters.getColumnsById(currentId))
    // const list = computed(() => store.state.posts.filter(post => post.columnId === currentId))
    const list = computed(() => store.getters.getPostsByCid(currentId))
    return {
      column,
      list
    }
  }
})
</script>

<style>

</style>
